package proxirabais.mobile.item;

import java.util.ArrayList;

import proxirabais.mobile.activity.ProxirabaisMobileActivity;

import messages.SystemMessage;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;


public class RabaisOverlayItems extends ItemizedOverlay {

	private ArrayList<MarkerOverlayItem> mOverlays = new ArrayList<MarkerOverlayItem>();
	private ProxirabaisMobileActivity mContext;

	public RabaisOverlayItems(Drawable defaultMarker, ProxirabaisMobileActivity context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context;
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	public void addOverlay(MarkerOverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}
	
	public void removeOverlay(OverlayItem overlay) {
		mOverlays.remove(overlay);
		populate();
	}

	@Override
	protected boolean onTap(int index) {
		 MarkerOverlayItem item = mOverlays.get(index);
	 
		 if(item.getTitle().equals(SystemMessage.NEW_MARKER))
			 mContext.getMarkerAction().addNewUserMarker(item);
		 else
			 mContext.getMarkerAction().showMarker(item);

		return true;
	}	

}
